import { ref } from "vue"
import axios from "axios"
import qs from 'qs';

const useUrlAxios = (url: string, data: object) => {
    const result = ref(null)
    const loading = ref<boolean>(true)
    const loaded = ref<boolean>(false)
    const error = ref(null)

    axios({
        method: 'post',
        url,
        data:qs.stringify(data)
    }).then((res) => {
        loading.value = false
        loaded.value = true
        result.value = res.data
    }).catch((err => {
        error.value = err
        loading.value = false
    }))

    return {
        result,
        loading,
        loaded,
        error
    }

}

export default useUrlAxios